package com.longsys.eventsourcing.core;


import lombok.Data;
import org.bson.types.ObjectId;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Data
public class EventAggregate {

    private String sourcingId;

    private String system;

    private String eventType;

    private String aggregateType;

    private Date eventTime;

    private EventUser eventUser;

    private ObjectId aggregateObjectId;

    private Map<String, Object> aggregateMap;

    public EventAggregate() {
    }

    public EventAggregate(String sourcingId, String system, String eventType, String aggregateType, Date eventTime, EventUser eventUser, ObjectId aggregateObjectId) {
        this.sourcingId = sourcingId;
        this.system = system;
        this.eventType = eventType;
        this.aggregateType = aggregateType;
        this.eventTime = eventTime;
        this.eventUser = eventUser;
        this.aggregateObjectId = aggregateObjectId;
    }

    /**
     * 添加聚合信息
     * @param key
     * @param value
     * @return
     */
    public EventAggregate addAggregateInfo(String key, Object value) {
        if (aggregateMap == null) {
            aggregateMap = new LinkedHashMap();
        }
        aggregateMap.put(key, value);
        return this;
    }
}
